package com.deram.ctin.rest.web.controller.web;

import com.deram.ctin.common.bean.Page;
import com.deram.ctin.common.bean.PageResult;
import com.deram.ctin.common.utils.ValidateUtils;
import com.deram.ctin.rest.web.result.web.WebCustomsInfoResult;
import com.deram.ctin.serv.customs.api.CustomsInfoApi;
import com.deram.ctin.serv.customs.api.CustomsTradeApi;
import com.deram.ctin.serv.customs.entity.CustomsInfo;
import com.deram.ctin.serv.customs.entity.CustomsTrade;
import com.deram.ctin.serv.customs.filter.CustomsTradeFilter;
import com.deram.ctin.serv.search.entity.solr.api.SolrCustomsInfoApi;
import com.deram.ctin.serv.search.entity.solr.bean.SolrCustomsInfo;
import com.deram.ctin.serv.search.entity.solr.search.WebCustomsSearchParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by xhw on 2017/09/14.
 */

@Api(tags = {"web - 海关接口"})
@RestController
@RequestMapping("/web/customs")
public class WebCustomsController {

    @Autowired
    private CustomsTradeApi customsTradeApi;

    @Autowired
    private CustomsInfoApi customsInfoApi;

    @Autowired
    private SolrCustomsInfoApi solrCustomsInfoApi;

    @ApiOperation(value = "海关信息搜索  ps:搜索条件是字符串类型的必须不为null，可以是空字符串 (暂时废弃)")
    @GetMapping("/search")
    public PageResult<SolrCustomsInfo> customsSearch(WebCustomsSearchParam param, Page page) {
        ValidateUtils.notEmpty(param.getKeywords(), "搜索关键字");
        PageResult<SolrCustomsInfo> pageResult = solrCustomsInfoApi.findByKeyWords(param, page.getPageNo(), page.getPageSize());
        return pageResult;
    }

//    @ApiOperation(value = "海关信息详情")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "ID", required = true, paramType = "path")
//    })
//    @GetMapping("/{id}")
//    public WebCustomsInfoResult info(@PathVariable Long id) {
//        WebCustomsInfoResult result = new WebCustomsInfoResult();
//        CustomsTrade customsTrade = customsTradeApi.find(id);
//        //result.setCustomsInfo(customsTrade);
//        return result;
//    }

    @ApiOperation(value = "海关分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, paramType = "path")
    })
    @GetMapping("/customsTradeSearch/{id}")
    public PageResult<CustomsTrade> customsTradeSearch(@PathVariable Long id, Page page) {
        CustomsTradeFilter customsTradeFilter = new CustomsTradeFilter();
        customsTradeFilter.setEnterId(id);
        PageResult<CustomsTrade> pageResult = customsTradeApi.search(customsTradeFilter, page.getPageNo(), page.getPageSize());
        return pageResult;
    }

    @ApiOperation(value = "海关详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, paramType = "path")
    })
    @GetMapping("/tradeInfo/{id}")
    public WebCustomsInfoResult tradeInfo(@PathVariable Long id) {
        WebCustomsInfoResult result = new WebCustomsInfoResult();
        CustomsTrade customsTrade = customsTradeApi.find(id);
        result.setCustomsTrade(customsTrade);
        return result;
    }

}
